Page({
  data: {
    current: 0,
    questions: [
      {
        id: 1,
        type: '单选题',
        text: '1+1=?',
        options: [
          { id: 1, label: 'A', text: '1', selected: false },
          { id: 2, label: 'B', text: '2', selected: false },
          { id: 3, label: 'C', text: '3', selected: false },
          { id: 4, label: 'D', text: '4', selected: false }
        ],
        answer: 2
      }
    ]
  },

  onLoad(options) {
    const id = options.id
    // 根据id获取题目列表
  },

  selectOption(e) {
    const optionId = e.currentTarget.dataset.id
    const questions = this.data.questions
    const currentQuestion = questions[this.data.current]
    
    currentQuestion.options.forEach(option => {
      option.selected = option.id === optionId
    })

    this.setData({
      questions
    })
  },

  prevQuestion() {
    if (this.data.current > 0) {
      this.setData({
        current: this.data.current - 1
      })
    }
  },

  nextQuestion() {
    if (this.data.current < this.data.questions.length - 1) {
      this.setData({
        current: this.data.current + 1
      })
    }
  },

  submitExercise() {
    wx.showModal({
      title: '确认提交',
      content: '确定要提交答案吗？',
      success: (res) => {
        if (res.confirm) {
          // 提交答案
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            success: () => {
              setTimeout(() => {
                wx.navigateBack()
              }, 1500)
            }
          })
        }
      }
    })
  }
}) 